package cn.agiledata.bank.linkbank.impl.abc;

import com.hitrust.trustpay.client.TrxResponse;
import com.hitrust.trustpay.client.b2c.QueryOrderRequest;
import cn.agiledata.bank.linkbank.exception.LinkBankException;
import cn.agiledata.bank.linkbank.logic.query.OrderQueryResponse;
import cn.agiledata.bank.linkbank.logic.query.OrderQuerySendable;
import cn.agiledata.bank.linkbank.logic.query.SingleOrderQueryRequest;

/**
 * 中国农业银行网上银行订单查询请求
 * 
 * @author 马贤波
 * 
 */
public final class AbcOrderQueryRequest implements SingleOrderQueryRequest,
        OrderQuerySendable {
    private QueryOrderRequest queryRequest;

    public AbcOrderQueryRequest() {
        this.queryRequest = new QueryOrderRequest();
        init();
    }

    private void init() {
        this.queryRequest.enableDetailQuery(true);
    }

    public String getOrderId() {
        return this.queryRequest.getOrderNo();
    }

    public void setOrderId(String orderId) {
        this.queryRequest.setOrderNo(orderId);
    }

    public OrderQueryResponse send() {
        TrxResponse trxResponse = this.queryRequest.postRequest();
        if (trxResponse.isSuccess()) {
            AbcOrder order = new AbcOrderBuilder().build(trxResponse);
            return OrderQueryResponse.getSuccessfulResponse(order);
        } else {
            String returnCode = trxResponse.getReturnCode();
            String errorMessage = trxResponse.getErrorMessage();
            return OrderQueryResponse.getFailedResponse(returnCode,
                    errorMessage);
        }
    }

    public void validate() throws LinkBankException {
    }

}
